package cn.easybuy.dao.Impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.easybuy.dao.BaseDao;
import cn.easybuy.dao.ProductDao;
import cn.easybuy.entity.Product;

public class ProductDaoImpl extends BaseDao implements ProductDao {

	@Override
	public List<Product> getProducts(int categoryLevel3Id) {
		List<Product> list = new ArrayList<Product>();
		ResultSet rs = null;
		String sql = "SELECT *  FROM `easybuy_product`  WHERE categoryLevel3Id=?";
		rs = this.exxcuteQuery(sql, categoryLevel3Id);
		try {
			while (rs.next()) {
				Product product = new Product();
				product.setId(rs.getInt("id"));
				product.setName(rs.getString("name"));
				product.setDescription(rs.getString("description"));
				product.setPrice(rs.getDouble("price"));
				product.setStock(rs.getInt("stock"));
				product.setCategoryLevel1Id(rs.getInt("categoryLevel1Id"));
				product.setCategoryLevel2Id(rs.getInt("categoryLevel2Id"));
				product.setCategoryLevel3Id(rs.getInt("categoryLevel3Id"));
				product.setFileName(rs.getString("fileName"));
				product.setIsDelete(rs.getInt("isDelete"));
				list.add(product);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			closeAll(connection, pstmt, rs);
		}
		return list;
	}

}
